package LC;

public class LC123 {
    public int removeElement(int[] A, int elem) {
        int  n  = A.length;
        for(int i=0; i<n; ++i) {
            if(A[i] == elem) {
                while(n>i && A[--n] == elem);
                A[i] = A[n];
            }
        }
        return n;
    }
}